/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Topka;

/**
 *
 * @author Asko
 */
import javax.swing.*;
import javax.swing.JFrame;
import javax.swing.event.*;
import java.awt.event.*;
import java.awt.*;
import java.awt.geom.Line2D;
import java.beans.*;
import java.util.logging.Level;
import java.util.logging.Logger;

public class DropDownTest extends JFrame {

    Stroke drawingStroke = new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{5}, 0);
    Line2D line = new Line2D.Double(20, 40, 100, 40);
    private static boolean isRunning = true;

    public void paint(Graphics g) {
        super.paint(g);
        Graphics2D g2d = (Graphics2D) g;
        int x = 100, y = 150;
        int ovalSize = 10;
        int i = 0 ;
        
        g2d.setColor(Color.red);

        double start = System.currentTimeMillis();
        while (System.currentTimeMillis() < start + 20000) {
            try {
                i++;
                if (x > 99 && x < 151 && y < 151 && y > 99) {
                    x++;
                    y--;
                    System.out.println("x =" + x + " y=" + y);
                }
                Thread.sleep(20);
                if (x > 149 && x < 201 && y < 151 && y > 99) {
                    x++;
                    y++;
                    System.out.println("x =" + x + " y=" + y);
                }
                Thread.sleep(20);
                if (x < 201 && x > 149 && y > 149 && y < 201) {
                    x--;
                    y++;
                    System.out.println("x =" + x + " y=" + y);
                }
                Thread.sleep(20);
                if (x < 151 && x > 99 && y > 151 && y < 201) {
                    x--;
                    y--;
                    System.out.println("x =" + x + " y=" + y);
                }
                Thread.sleep(20);
                System.out.println("Loop number " + i  + " has ended");
                g2d.fillOval(y, (int) Math.sqrt(Math.abs(100 - y)),
                        ovalSize, ovalSize);
                repaint();
                
            }
            /*g2d.setStroke(drawingStroke);
            g2d.drawOval(20, 40, 100, 100);
            g2d.setColor(Color.RED);
            int i = 62 ;
            int j = 47 ;
            int size = 10 ;
            // while (true) {
            g2d.fillOval(i, j, size, size);*/
            // }
            catch (InterruptedException ex) {
                Logger.getLogger(DropDownTest.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        /*g2d.setStroke(drawingStroke);
         g2d.drawOval(20, 40, 100, 100);
         g2d.setColor(Color.RED);
         int i = 62 ;
        
         int j = 47 ;
         int size = 10 ;
         // while (true) {
         g2d.fillOval(i, j, size, size);*/
        // }
    }

    public static void setBool(boolean isRun) {
        isRunning = isRun;
    }

    public static void main(String args[]) {
        final JFrame frame = new DropDownTest();
        /*  frame.addKeyListener(new KeyListener() {

         @Override
         public void keyTyped(KeyEvent e) {
         System.out.println("Doing nothing here");
         }

         @Override
         public void keyPressed(KeyEvent e) {
         if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
         setBool(false)   ;
         frame.dispose();
         System.out.println("Frame disposed");
         }
         }

         @Override
         public void keyReleased(KeyEvent e) {
         System.out.println("Following key has been released" +
         e.getKeyChar());
         }
         });*/
        frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
        frame.setSize(500, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}
